// pages/home/home.js
var utils = require('../../utils/utils.js')
var _utils = utils;
var _http = require('../../utils/httpUtils.js')
var loginx = require('../../utils/login.js')
var mapUtils = require('../../utils/map.js')
var anim = require('../../utils/animation.js')
let app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isLinkage:false, //是否使用左右联动效果
        showGoodsDetail: false,
        showCourseInfo:null,
        classifySeleted: "",
        distance: '0m',
        bannerList: [
            // { pic: 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640' }
        ],
        goods: {
            // 'x1': {
            //     id: 'x1',
            //     title: 'History of Columbia  University  Korean  historiography',
            //     pic: '/images/common/img4.png',
            //     sold: 1014,
            //     tutor: 'William Kirby',
            //     price: 2,
            //     type: 't1'
            // },
            // 'x2': {
            //     id: 'x2',
            //     title: 'History of Columbia  University  Korean  historiography',
            //     pic: '/images/common/img4.png',
            //     sold: '金针菇金针菇金针菇金针菇金针菇金针菇金针菇金针菇',
            //     tutor: 'William Kirby',
            //     price: 3,
            //     type: 't1'
            // },
            // 'x3': {
            //     id: 'x3',
            //     title: 'History of Columbia  University  Korean  historiography',
            //     pic: '/images/common/img4.png',
            //     sold: 1030,
            //     tutor: 'William Kirby',
            //     price: 2,
            //     type: 't2'
            // },
            // 'x4': {
            //     id: 'x4',
            //     title: 'History of Columbia  University  Korean  historiography',
            //     pic: '/images/common/img4.png',
            //     sold: 1059,
            //     tutor: 'William Kirby',
            //     price: 1,
            //     type: 't3'
            // },

        },
        goodsList: [

            //     {
            //     id: 't1',
            //     classifyName: '1v1 research',
            //     icon: '/images/tree/one.png',
            //     goods: ['x1', 'x2']
            // },
            // {
            //     id: 't2',
            //     classifyName: 'Online\nresearch',
            //     icon: '/images/tree/two.png',
            //     goods: ['x3']
            // },
            // {
            //     id: 't3',
            //     classifyName: 'ASC Summer\nProject',
            //     icon: '/images/tree/three.png',
            //     goods: ['x4', 'x1']
            // },
            // {
            //     id: 't4',
            //     classifyName: 'New York Field\nResearch Project',
            //     icon: '/images/tree/four.png',
            //     goods: ['x4', 'x3']
            // }
        ],
        cart: {
            count: 0,
            total: 0,
            goodsTNum: 0,
            list: {},
            type: {}
        },
        cart2: {
            count: 30,
            total: 22,
            goodsTNum: 0,
            list: {
                'x1': {
                    count: 3,
                    id: 'x1',
                    name: '娃娃菜',
                    pic: 'http://img0.imgtn.bdimg.com/it/u=2509945305,1703380347&fm=26&gp=0.jpg',
                    sold: 1014,
                    price: 2
                },
                'x2': {
                    count: 5,
                    id: 'x2',
                    name: '金针菇',
                    pic: 'http://img0.imgtn.bdimg.com/it/u=2893494008,2884679342&fm=26&gp=0.jpg',
                    sold: '金针菇金针菇金针菇金针菇金针菇金针菇金针菇金针菇',
                    price: 3
                },
                'x3': {
                    count: 22,
                    id: 'x3',
                    name: '方便面',
                    pic: 'http://img3.imgtn.bdimg.com/it/u=2838277590,3010570951&fm=26&gp=0.jpg',
                    sold: 1030,
                    price: 2
                },
            }
        },
        showCartDetail: false,
        leftsc: 0, //左边滚动菜单的滚动距离
        wh: 0, //整个设备屏幕的高度
        topt: 0, //顶部固定框的高度
        goodshArr: [], //所有商品+分类名称的高度
        goodsch: 0, //右边小分类高度
        showCart: false, //是否显示购物车
        cartHeight: 0, //底部购物车的高度
        chooseGoodsHeight: 600, //显示出来的购物车的商品的高度
        oauthUser: { "k": "1" },
        utoken: wx.getStorageSync('token'), //登陆的token
        eStatus: 1,// 申请状态
        isnullgoods: true

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var SystemInfo = wx.getSystemInfoSync()
        console.log(SystemInfo.windowHeight);
        this.setData({
            wh: SystemInfo.windowHeight
        })

        let _this = this;
        //获取banner列表
        getBannerList(this);

       
        let ou = wx.getStorageSync("token");
        // if(!ou){
        loginx.loginx(this, function (res) {
            // 登陆成功之后
            // 开始请求用户个人信息
            //判断缓存中的用户信息 
            //console.log(res);
            //textt();

        });
        // return;
        // }


        //判断缓存中是否有商品在购物车
        // this.confirmCartGoods();

        //获取课程分类
        getItemCate(this);
         //获取缓存中的数据
         if(this.data.isLinkage){
             let goodsArr = wx.getStorageSync('goodsArr');
             let cateList = wx.getStorageSync('cateList');
             if (goodsArr && cateList) {
                 this.setData({
                     goods: goodsArr,
                     goodsList: cateList,
                     isnullgoods: false,
                 })
             } else {
                 this.setData({
                     isnullgoods: true,
                 })
                
             }
         }

         setTimeout(() => {
            _this.setData({
                goodsList: _this.data.goodsList,
                goods:_this.data.goods,
            })
            wx.setStorageSync('cateList', _this.data.goodsList);
         }, 2500);
         
    },
    onShow: function () {
        //getLoc(this);
        // this.setData({
        //     classifySeleted: this.data.goodsList[0].id2
        // });

        console.log("onShow......");

        let _this = this;
        let query = wx.createSelectorQuery();

        //获得顶部固定块的高度
        query.select('.banner-l').boundingClientRect(function (rect) {
            if(rect){

                if (!_this.data.topt) {
                    _this.setData({
                        topt: rect.height
                    })
                }
            }
        }).exec();

        //获取每个商品的高度
        let query2 = wx.createSelectorQuery();
        query2.select('.goods').boundingClientRect(function (rect) {
            if(rect){
                if (!_this.data.goodsh) {
                    _this.setData({
                        goodsh: rect.height + 15
                    })
                }
            }
        }).exec();
        //获取右边分类的高度
        let query3 = wx.createSelectorQuery();
        query3.select('.title').boundingClientRect(function (rect) {
            if(rect){

                if (!_this.data.goodsch) {
                    _this.setData({
                        goodsch: rect.height
                    })
                }
            }
            console.log(_this.data['goodsch']);
        }).exec();
        // query3.select('.banner-l').boundingClientRect(function(rect) {
        //     if (!_this.data.bannerHeight) {
        //         _this.setData({
        //             bannerHeight: rect.height
        //         })
        //     }
        // }).exec();
        setTimeout(function () {
            //计算每个分类下面的所有商品的高度
            //有数据的时候 直接在返回数据后请求
            var goodshArr = {};
            var h = 0;
            _this.data.goodsList.forEach(function (classify, i) {
                //每个分类下的高度是   商品+小分类高度
                if(classify.goods){

                    var _h = _this.data.goodsch + classify.goods.length * _this.data.goodsh;
                    h += _h;
                    //console.log(i);
                    goodshArr[classify.id2] = h;
                }
            });
            // console.log(goodshArr);
            _this.setData({
                goodshArr: goodshArr
            })
        }, 3000)



        setTimeout(function () {
            //判断缓存中的用户信息 
            let ou = wx.getStorageSync("token");
            let eStatus = wx.getStorageSync("eStatus");
            console.log(_this.data.utoken);
            _this.setData({
                utoken: ou,
                eStatus: eStatus
            })
            //如果申请状态不是成功的, 每次都要去查询当前的状态
            // _this.checkApplyStatus(_this);
            // return;
            console.log(ou);

            if (ou) {

                _http.post(_http.enrollStatus, {}, function (da) {
                   
                    _this.setData({
                        eStatus2: da.data.user_enroll
                    })
                    _this.checkApplyStatus(_this);

                })
            }
        }, 2000)

    },
    checkApplyStatus: function (_this) {
        let dl = _this.data.eStatus2;
        let dlcache = _this.data.eStatus;
        let dty = _this.data.goodsList;
        if(!dl){
           dl = dlcache;
        }
        //取出来所报名的项目
        for (let i = 0; i < dl.length; i++) {
            const d = dl[i];  //审核的列表
            for (let k = 0; k < dlcache.length; k++) {
                const dcache = dlcache[k];
                //和缓存中的审核结果比较, 如果是已经显示过弹窗的话 就直接赋值并且不再显示了
                if(dcache.cate_id == d.cate_id){
                    d.show = dcache.show;
                }
            }

            //比对已有的项目  ,相等并且通过则改变状态
            for (let k = 0; k < dty.length; k++) {
                const dt = dty[k]; //this.data 的列表
                if (dt.id == d.cate_id) {  //放入锅两个id相等, 则把审核的状态信息赋值

                    //判断状态:如果是成功的话,则去提示弹窗,并标记已经提示过了
                    if ((d.status == 1 || d.status == 2)) {
                        if(!d.show){
                            //赋值提示标示
                            //设置已经提示过了标识
                            dl[i].show = true;
                            if(d.course){
                                d.course.id = d.course_id;
                                d.course.status = d.status;
                            }else{
                                d.course = {};
                                d.course.id = d.course_id;
                                d.course.status = d.status;
                            }
                            _this.setData({
                                showGoodsDetail:true,
                                showCourseInfo:d.course
                            })
                        }
                    }else{
                        dl[i].show = false;
                    }


                    _this.setData({
                        ['goodsList[' + k + '].state']: d.status,  //将查出来的状态放在每一个分类下面 , 
                        ['goodsList2[' + k + '].state']: d.status  //将查出来的状态放在每一个分类下面 , 
                    })

                    _this.setData({
                        goodsList: _this.data.goodsList,
                        goodsList2: _this.data.goodsList2,
                    })
                    wx.setStorageSync('cateList', _this.data.goodsList2);
                }
            }
        }
        console.log(dl);
        wx.setStorageSync('eStatus', dl);
    },
    ttest: function (e) {
        let ee = e.currentTarget.dataset.goodsListInfo;
        console.log(e);
    },
    confirmCartGoods: function () {
        let _this = this;
        var cartgoods = wx.getStorageSync('cartGoods');
        console.log(cartgoods);
        if (cartgoods) {
            _this.setData({
                cart: cartgoods,
                showCart: true,
            })
            this.getCartHeight(this);
        }
    },
    //选种商品打开弹窗 显示商品详情页面
    showGoodsDetail: function (e) {

        // if (this.data.eStatus == 0) {
        //     _utils.toast('报名正在审核中');
        //     return;
        // }
        this.setData({
            showGoodsDetail:false
        })
        var idd = e.currentTarget.dataset.id;
        console.log(idd);
        let _this = this;
        // console.log(_this.data.goods[idd]);
        // anim.opacity(_this, 'maskAnimation', 'open');
        // anim.scale(_this, 'open', 'showGoodsDetail');
        // _this.setData({
        //     chooseGoodsInfo: _this.data.goods[idd]
        // })
        // _this.setData({
        // 	showGoodsDetail:true,
        // })
        //跳转到详情页面
        wx.navigateTo({
            url: '/pages/asc/kechenginfo/kechenginfo?id=' + idd,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
    showSignUpPage: function (e) {
        console.log("去注册页面");
        //未登录去注册页面
        let k = e.currentTarget.dataset.kc;
        app.other = { t: k.tutor_name.cn_name, p: k.cate_name.class_name, tid: k.id, cate_id: k.cates_id }
        wx.switchTab({
            url: '/pages/asc/apple/appleType/appleType',
        })
    },
    closeGoodsDetail: function (e) {
        let _this = this;
        // anim.opacity(_this, 'maskAnimation', 'close','showGoodsDetail');
        // anim.scale(_this, 'close', 'showGoodsDetail');
        _this.setData({
            showGoodsDetail: false
        })

    },
    goChooseGoods: function () {
        this.closeGoodsDetail();
        console.log('关闭弹窗,继续挑选商品');
    },
    powerDrawer: function (e) {
        utils.showModel(this, e.currentTarget.dataset.statu);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        console.log('done');
    },
    getCartHeight: function (_this) {

        //改变菜单的高度
        let query3 = wx.createSelectorQuery();
        query3.select('.cart-1').boundingClientRect(function (rect) {
            console.log(rect.height);
            if (!_this.data.cartHeight) {
                _this.setData({
                    cartHeight: rect.height
                })
            }
        }).exec();
    },
    //添加商品
    tapAddCart: function (e) {
        let _this = this;
        console.log(e.currentTarget.dataset.id);
        this.addCart(e.currentTarget.dataset.id);
        //点击添加商品将购物车显示出来
        if (!this.data.showCart) {
            this.setData({
                showCart: true
            })
            this.getCartHeight(this);
        }
    },
    //将商品添加到购物车里面
    addCart: function (id) {
        //var num = this.data.cart.list[id] || 0;
        //this.data.cart.list[id] = num + 1;
        //this.countCart();
        //1获取到id,拿到商品信息
        let _this = this;
        var goods = this.data.goods[id];
        var key = 'cart.list.' + goods.id;
        var typeKey = 'cart.type.' + goods.type;
        //2判断购物车是否有此商品
        if (_this.data.cart.list[id]) {
            console.log(_this.data.cart.type[goods.type]);

            goods['count'] = _this.data.cart.list[id].count + 1;
            _this.setData({
                [key]: goods,
                'cart.count': _this.data.cart.count + 1,
                'cart.total': _this.data.cart.total + goods.price,
                [typeKey]: _this.data.cart.type[goods.type] + 1
            })
        } else {
            console.log(_this.data[typeKey]);
            goods['count'] = 1;
            _this.setData({
                [key]: goods,
                'cart.count': _this.data.cart.count + 1,
                'cart.total': _this.data.cart.total + goods.price,
                [typeKey]: _this.data.cart.type[goods.type] ? _this.data.cart.type[goods.type] + 1 : 1
            })
        }
        wx.setStorageSync("cartGoods", _this.data.cart)
    },
    //删除商品
    tapReduceCart: function (e) {
        this.reduceCart(e.currentTarget.dataset.id);
        //改变菜单的高度
        // if (this.data.showCart) {
        //     this.setData({
        //         showCart: false,
        //         cartHeight: 0
        //     })

        // }
    },
    clearCart: function () {
        this.clearCartGoods();
    },
    //清空购物车商品
    clearCartGoods: function (_this) {
        console.log(_this);
        _this = _this ? _this : this;
        console.log(_this);
        var cart = {
            count: 0,
            total: 0,
            goodsTNum: 0,
            list: {},
            type: {}
        }
        _this.setData({
            showCart: false,
            showCartDetail: false,
            cartHeight: 0,
            cart: cart
        })

        wx.removeStorageSync("cartGoods");
    },

    reduceCart: function (id) {
        let _this = this;
        var goods = this.data.goods[id];
        var key = 'cart.list.' + goods.id;
        //2判断购物车是否有此商品
        console.log(123);
        goods['count'] = _this.data.cart.list[id].count - 1;
        var allcount = _this.data.cart.count - 1;
        var typeKey = 'cart.type.' + goods.type;
        _this.setData({
            [key]: goods,
            'cart.count': allcount,
            'cart.total': _this.data.cart.total - goods.price,
            [typeKey]: _this.data.cart.type[goods.type] - 1
        })
        if (goods.count == 0) {
            console.log('删除干净了');
            delete _this.data.cart.list[id];
        }
        //重新计算商品的高度
        var ll = Object.keys(this.data.cart.list).length;
        this.setData({
            chooseGoodsHeight: 120 * ll + 10,
            'cart.goodsTNum': ll
        })
        if (allcount == 0) {
            this.clearCartGoods(_this);
        } else {
            wx.setStorageSync("cartGoods", _this.data.cart)
        }
        // var num = this.data.cart.list[id] || 0;
        // if (num <= 1) {
        //     delete this.data.cart.list[id];
        // } else {
        //     this.data.cart.list[id] = num - 1;
        // }
        // this.countCart();
    },
    countCart: function () {
        console.log('countcart');
        var count = 0,
            total = 0;
        for (var id in this.data.cart.list) {
            var goods = this.data.goods[id];
            count += this.data.cart.list[id];
            total += goods.price * this.data.cart.list[id];
        }
        this.data.cart.count = count;
        this.data.cart.total = total;
        this.setData({
            cart: this.data.cart
        });
    },
    // onPullDownRefresh: function () {
    //     // this.onLoad();
    //     //获取缓存中的数据
    //     return;
    //     let goodsArr = wx.getStorageSync('goodsArr');
    //     let cateList = wx.getStorageSync('cateList');
    //     this.setData({
    //         goods: goodsArr,
    //         goodsList: cateList,
    //     })
    //     wx.stopPullDownRefresh({
    //         complete: (res) => { },
    //     })
    // },
    follow: function () {
        this.setData({
            followed: !this.data.followed
        });
    },
    onLeftScroll: function (e) {
        // console.log(e);
        // console.log(e.detail.scrollTop);
    },
    onSelectFil: function () {
        let query = wx.createSelectorQuery();
        var _this = this;
        query.select('.active').boundingClientRect(function (rect) {
            // console.log(rect);
            //   console.log("top:" + rect.top);
            // console.log("bom:" + rect.bottom);
            if (!_this.data.leftActive) {
                _this.setData({
                    leftActive: rect.height
                })
            }
            //如果到了第一个分类, 直接拉到最上面去
            if (!_this.data.scrollDown) {
                _this.setData({
                    leftsc: 0
                })
                return;
            }
            if (rect.top < 0) {
                // console.log(rect.top,rect.height , _this.data.leftsc);
                // if (rect.top < rect.height){
                // 	_this.setData({
                // 		leftsc: _this.data.leftsc - rect.top
                // 	})
                // }else{
                _this.setData({
                    leftsc: _this.data.leftsc - rect.height
                })
                // }
            }
            if (rect.bottom > _this.data.wh - _this.data.cartHeight) {
                _this.setData({
                    leftsc: _this.data.leftsc + rect.height / 2
                })
            }
        }).exec();
    },
    showMap: function () {
        mapUtils.getLocation(function (res) {
            console.log(res);
            // wx.openLocation({
            // 	latitude:res.latitude,
            // 	longitude:res.longitude,
            // 	scale: 18
            // })
        })

        wx.navigateTo({
            url: './location/location',
        })

    },
    onGoodsScroll: function (e) {
        if(!this.data.isLinkage){
            return;
        }
        if (e.detail.scrollTop > this.data.goodsList[0].goods.length * this.data.goodsh && !this.data.scrollDown) {
            this.setData({
                scrollDown: true
            });
        } else if (e.detail.scrollTop < this.data.goodsList[0].goods.length * this.data.goodsh && this.data.scrollDown) {
            this.setData({
                scrollDown: false
            });
        }
        var h = 0,
            classifySeleted,
            _this = this,
            goodshArr = this.data.goodshArr,
            scrollTop = e.detail.scrollTop;


        //console.log('-------------------------------------');

        //console.log(scrollTop);
        // var scale = e.detail.scrollWidth / (this.data.wh),
        //     scrollTop = e.detail.scrollTop / scale,
        //     h = 0,

        //     len = this.data.goodsList.length;
        // this.data.goodsList.forEach(function(classify, i) {
        // 	var _h = _this.data.leftActive/2 + classify.goods.length * (_this.data.goodsh*2);
        // 	//console.log(h, scrollTop);
        // 	if (scrollTop >= h) {
        //         classifySeleted = classify.id; 
        //     }
        //     h += _h;
        // });
        //console.log(classifySeleted);
        // console.log(scrollTop);

        for (var item in goodshArr) {
            let gar = goodshArr[item];
            //console.log(item + ":" + gar);
            if (scrollTop + 3 < gar) {
                classifySeleted = item;
                break;
            }
        }

        this.setData({
            classifySeleted: classifySeleted
        });
        this.onSelectFil();
    },
    tapClassify: function (e) {
        var id = e.currentTarget.dataset.id;
        var id2 = e.currentTarget.dataset.idy;
        
        //设置选中样式
        var self = this;
        setTimeout(function () {
            self.setData({
                classifySeleted: id
            });
        }, 100);
        //判断是否联动
        if(this.data.isLinkage){
            //设置右边滑动关联id
            this.setData({
                classifyViewed: id
            });
        }else{
            var ind = e.currentTarget.dataset.index;
            getItemListOne(this,id2,ind);
        }
    },
    //授权信息
    bindGetUserInfo: function (e) {
        console.log(e);
        let _this = this;
        loginx.loginx(this, _this.onShow())
        // if (!this.data.oauthUserInfo) {
        //     wx.setStorage({
        //         key: 'oauthUser',
        //         data: e.detail.userInfo
        //     })
        //     this.setData({
        //         oauthUser: e.detail.userInfo
        //     })
        // }
    },
    //显示购物车详情
    showCartDetail: function () {
        var _this = this;

        if (!_this.data.showCartDetail) {
            anim.opacity(_this, 'maskAnimation', 'close');
            anim.translateY(this, 'open', 'showCartDetail');
        } else {
            anim.translateY(_this, 'close', 'showCartDetail');
            anim.opacity(_this, 'maskAnimation', 'close');
        }
        var ll = Object.keys(this.data.cart.list).length;
        console.log(ll);
        this.setData({
            chooseGoodsHeight: 120 * ll + 10,
            'cart.goodsTNum': ll
        })


    },
    hideCartDetail: function () {
        var _this = this;
        anim.translateY(_this, 'close', 'showCartDetail');
        anim.opacity(_this, 'maskAnimation', 'close');
    },
    submit: function (e) {

    },
    toRegister: function () {
        wx.navigateTo({
            url: '/pages/register/registerOne/registerOne',
        })
    },
    toDetail: function () {
        wx.navigateTo({
            url: '/pages/classDetail/classDetail',
        })
    },
    goPayPage: function () {
        utils.toast('结算中', 2);
        wx.navigateTo({
            url: '/pages/payOrder/payOrder',
        })
    },
    donothing: function () { }
})

function getLoc(_this) {
    var ll = 0;
    mapUtils.getLocation(function (res) {
        ll = mapUtils.getDistance(30.275385, 119.96195, res.latitude, res.longitude);
        console.log(ll + "米");
        _this.setData({
            distance: ll / 1000 > 1 ? (ll / 1000).toFixed(1) + 'km' : ll + 'm'
        })
    })
}

function getBannerList(_this) {
    _http.postn(_http.banner, {}, function (res) {
        console.log(res.data);
        _this.setData({
            bannerList: res.data.banner
        })
    })
}
function getItemCate(_this) {
    _http.postn(_http.projectCate, {}, function (res) {
        var list = res.data.list
        var mList = [];
        for (let i = 0; i < list.length; i++) {
            const obj = list[i];

            switch (obj.id) {
                case 1:
                    obj.icon = '/images/tree/one.png';
                    break;
                case 2:
                    obj.icon = '/images/tree/two.png';
                    break;
                case 3:
                    obj.icon = '/images/tree/three.png';
                    break;
                case 4:
                    obj.icon = '/images/tree/four.png';
                    break;
                default:
                    obj.icon = '/images/tree/one.png';
                    break;
            }
            obj.id2 = "as_" + obj.id;
            obj.classifyName = obj.class_name;
            obj.state = -1;
            //默认选中第一个分类
            if (i == 0) {
                _this.setData({
                    classifySeleted: obj.id2
                });
                if(!_this.data.isLinkage){
                    getItemListOne(_this,obj.id,i);
                }
            }
            //将每一个分类数据处理好装在list中
            mList.push(obj);

        }
        if (_this.data.isnullgoods) {
            _this.setData({
                goodsList: mList,
                goodsList2: mList,
            })
        } else {
            _this.setData({
                goodsList2: mList,
            })
        }

        //处理好分类数据后 ,开始加载全部分类下面的所有数据列表
        if(_this.data.isLinkage){
            getItemList(_this);
        }
    })
}
function getItemList(_this) {
    // wx.setStorageSync('goodsInfo', {});
    var li = _this.data.goodsList;
    console.log(li);
    //循环查询每一个分类下面的所有数据
    for (let i = 0; i < li.length; i++) {
        var oj = li[i];
        console.log(oj)
        var catid = oj.id; //分类id
        getItemListOne(_this,catid);
    }


}

function getItemListOne(_this,cid,index){
    if(!_this.data.isLinkage){
        _this.setData({
            goods:{}
        })

        let gts = _this.data.goodsList;
        for (let i = 0; i < gts.length; i++) {
            const g = gts[i];
            var k = "goodsList[" + i + "].goods";
            _this.setData({
                [k]:[]
            })
        }

    }
    _http.postn(_http.projectList, { "list_row": 1000, "page": "1", "cates_id": cid }, function (res2) {

        var list2 = res2.data.list;
        var gt = []; //定义商品id数组,为了和分类关联

        for (let k = 0; k < list2.length; k++) {
            const k2 = list2[k];
            gt.push("asc" + k2.id);
            if(cid == 4){
                k2.non = true;
            }
            //保存商品到集合中
            var sg = "goods.asc" + k2.id + "";
            var sg2 = "goods2.asc" + k2.id + "";
            if (_this.data.isnullgoods) {
                _this.setData({
                    [sg]: utils.formatData(k2),
                    [sg2]: utils.formatData(k2),
                })
            } else {
                _this.setData({
                    [sg2]: utils.formatData(k2),
                })
            }
        }
        //把当前分类下的课程id保存起来
        var k = "goodsList2[" + index + "].goods";
        var k2 = "goodsList[" + index + "].goods";
        console.log(k);
        _this.setData({
            [k]: gt,
            [k2]: gt
        })
    })

    // setTimeout(() => {
    //     wx.setStorageSync('goodsArr', _this.data.goods2);
    // }, 5000);
}

function textt() {
    console.log(112233);
}
